/**
*      author: Y_Yao
*      created: 2025-03-22 11:09:58
**/

#include<bits/stdc++.h>

#define int LL
using namespace std;
using LL = long long;
const LL LLINF = 9e18;
const int INF = 0x3f3f3f3f;
const int N = 1e18 + 7;
int n;
unordered_map<int,int> f;
int ans;

int search(int x)
{
    if(x == 0)
    {
        return 1;
    }
    int x1 = x / 2;
    int x2 = x / 3;
    int f1,f2;
    if(f.count(x1))f1 = f[x1];
    else
    {
        f1 = search(x1);
        f[x1] = f1;
    }
    if(f.count(x2)) f2 = f[x2];
    else
    {
        f2 = search(x2);
        f[x2] = f2;
    }
    return f[x1] + f[x2];
}

void solve()
{
    cin >> n;
    ans = search(n);
    cout << ans << endl;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int t = 1;
    //cin >> t;
    while(t--)
    {
        solve();
    }
    return 0;
}